# 设置前缀快捷键
set -g prefix2 C-k                        # GNU-Screen compatible prefix
bind C-k send-prefix -2

# 使用vi风格的快捷键设置
#setw -g mode-keys vi

# 解决less中搜索不高亮的问题
set -ga terminal-overrides ',*:sitm@,ritm@'

# 开启鼠标模式，支持鼠标选择面板、调整面板大小、选择窗口
set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on


##### reference: https://raw.githubusercontent.com/gpakosz/.tmux/master/.tmux.conf


# cat << ►_◄ > /dev/null
# (‑●‑●)> released under the WTFPL v2 license, by Gregory Pakosz (@gpakosz)


# -- general -------------------------------------------------------------------

set -g default-terminal "screen-256color" # colors!
setw -g xterm-keys on
set -s escape-time 0                      # fastest command sequences
set -sg repeat-time 600                   # increase repeat timeout
#set -s quiet on                           # disable various messages

#set -g prefix2 C-a                        # GNU-Screen compatible prefix
#bind C-a send-prefix -2

set -g history-limit 5000                 # boost history

# edit configuration
#bind e new-window -n '~/.tmux.conf.local' "sh -c '\${EDITOR:-vim} ~/.tmux.conf.local && tmux source ~/.tmux.conf && tmux display \"~/.tmux.conf sourced\"'"
bind e new-window -n '~/.tmux.conf' "sh -c '\${EDITOR:-vim} ~/.tmux.conf && tmux source ~/.tmux.conf && tmux display \"~/.tmux.conf sourced\"'"

# reload configuration
bind r source-file ~/.tmux.conf \; display '~/.tmux.conf sourced'

# see https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
if 'which -s reattach-to-user-namespace' 'set -g default-command "exec initializing... 2> /dev/null & reattach-to-user-namespace $SHELL -l"'


# -- display -------------------------------------------------------------------

set -g base-index 1         # start windows numbering at 1
setw -g pane-base-index 1   # make pane numbering consistent with windows

setw -g automatic-rename on # rename window to reflect current program
set -g renumber-windows on  # renumber windows when a window is closed

set -g set-titles on                        # set terminal title
set -g set-titles-string '#h ❐ #S ● #I #W'

set -g display-panes-time 800 # slightly longer pane indicators display time
set -g display-time 1000      # slightly longer status messages display time
set -g status-interval 10     # redraw status line every 10 seconds
setw -g clock-mode-style 24   # 24 hour clock
bind -n C-l send-keys C-l \; run 'tmux clear-history'   # clear both screen and history

# activity
set -g monitor-activity on
set -g visual-activity off


# -- navigation ----------------------------------------------------------------

# find session
bind C-f command-prompt -p find-session 'switch-client -t %%'

# pane navigation
bind -r h select-pane -L  # move left
bind -r j select-pane -D  # move down
bind -r k select-pane -U  # move up
bind -r l select-pane -R  # move right
bind > swap-pane -D       # swap current pane with the next one
bind < swap-pane -U       # swap current pane with the previous one

# maximize current pane
#bind + run 'cut -c3- ~/.tmux.conf | sh -s maximize_pane'

# pane resizing
bind -r H resize-pane -L 2
bind -r J resize-pane -D 2
bind -r K resize-pane -U 2
bind -r L resize-pane -R 2

# window navigation
unbind n
unbind p
bind -r C-h previous-window # select previous window
bind -r C-l next-window     # select next window
bind Tab last-window        # move to last active window

# toggle mouse
#bind m run "cut -c3- ~/.tmux.conf | sh -s toggle_mouse"


# -- urlview -------------------------------------------------------------------

#bind U run "cut -c3- ~/.tmux.conf | sh -s urlview #{pane_id}"


# -- facebook pathpicker -------------------------------------------------------

#bind F run "cut -c3- ~/.tmux.conf | sh -s fpp #{pane_id}"


# -- list choice ---------------------------------------------------------------

bind -t vi-choice h tree-collapse
bind -t vi-choice l tree-expand
run -b 'tmux bind -t vi-choice K start-of-list 2> /dev/null'
run -b 'tmux bind -t vi-choice J end-of-list 2> /dev/null'
bind -t vi-choice H tree-collapse-all
bind -t vi-choice L tree-expand-all
bind -t vi-choice Escape cancel


# -- edit mode -----------------------------------------------------------------

# the following vi-copy bindings match my vim settings
#   see https://github.com/gpakosz/.vim.git
bind -ct vi-edit H start-of-line
bind -ct vi-edit L end-of-line
bind -ct vi-edit q cancel
bind -ct vi-edit Escape cancel


# -- copy mode -----------------------------------------------------------------

bind Enter copy-mode # enter copy mode
bind b list-buffers  # list paster buffers
bind p paste-buffer  # paste from the top pate buffer
bind P choose-buffer # choose which buffer to paste from

# the following vi-copy bindings match my vim settings
#   see https://github.com/gpakosz/.vim.git
bind -t vi-copy v begin-selection
bind -t vi-copy C-v rectangle-toggle
bind -t vi-copy y copy-selection
bind -t vi-copy Escape cancel
bind -t vi-copy H start-of-line
bind -t vi-copy L end-of-line

# copy to Mac OSX pasteboard
#if -b 'which -s reattach-to-user-namespace' 'bind y run "tmux save-buffer - | reattach-to-user-namespace pbcopy"'


# -- user defined --------------------------------------------------------------

#if '[ -f ~/.tmux.conf.local ]' 'source ~/.tmux.conf.local'


# -- 8< ------------------------------------------------------------------------

#run 'cut -c3- ~/.tmux.conf | sh -s apply_configuration'


##### reference end
